

export default class InputListenerMgr<T>{
    protected listeners: T[] = []

    protected tempList: T[] = []
    on(listener: T) {
        let index = this.listeners.indexOf(listener)
        if (index >= 0) {
            return;
        }
        this.listeners.push(listener)
    }

    off(listener: T) {
        let index = this.listeners.indexOf(listener)
        if (index >= 0) {
            this.listeners.splice(index, 1)
        }
    }

    get length() {
        return this.listeners.length;
    }

    get list() {
        this.tempList.length = 0;
        for (let index = 0; index < this.listeners.length; index++) {
            const element = this.listeners[index];
            this.tempList.push(element)
        }
        return this.tempList;
    }

}